//serveice层
import CLRequest from './request'
import { BASE_URL, TIME_OUT } from './request/config'

import localCache from '@/utils/cache'

const clRequest = new CLRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestHook: (config) => {
      //携带token的拦截
      const token = localCache.getCache('token')
      if (token && config && config.headers) {
        config.headers.Authorization = `Bearer ${token}`
      }
      return config
    },
    requestHookCatch(error) {
      return error
    },
    responseHook(res) {
      return res
    }
  }
})

export default clRequest
